package org.dromara.yuanshidian.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.yuanshidian.domain.vo.Ab05Vo;
import org.dromara.yuanshidian.domain.bo.Ab05Bo;
import org.dromara.yuanshidian.service.IAb05Service;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 个人账户总账
 *
 * @author Lion Li
 * @date 2025-01-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/yuanshidian/ab05")
public class Ab05Controller extends BaseController {

    private final IAb05Service ab05Service;

    /**
     * 查询个人账户总账列表
     */
    //@SaCheckPermission("yuanshidian:ab05:list")
    @GetMapping("/list")
    public TableDataInfo<Ab05Vo> list(Ab05Bo bo, PageQuery pageQuery) {
        return ab05Service.queryPageList(bo, pageQuery);
    }

    /**
     * 导出个人账户总账列表
     */
    @SaCheckPermission("yuanshidian:ab05:export")
    @Log(title = "个人账户总账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Ab05Bo bo, HttpServletResponse response) {
        List<Ab05Vo> list = ab05Service.queryList(bo);
        ExcelUtil.exportExcel(list, "个人账户总账", Ab05Vo.class, response);
    }

    /**
     * 获取个人账户总账详细信息
     *
     * @param ID 主键
     */
    @SaCheckPermission("yuanshidian:ab05:query")
    @GetMapping("/{ID}")
    public R<Ab05Vo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(ab05Service.queryById(ID));
    }

    /**
     * 新增个人账户总账
     */
    @SaCheckPermission("yuanshidian:ab05:add")
    @Log(title = "个人账户总账", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Ab05Bo bo) {
        return toAjax(ab05Service.insertByBo(bo));
    }

    /**
     * 修改个人账户总账
     */
    @SaCheckPermission("yuanshidian:ab05:edit")
    @Log(title = "个人账户总账", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Ab05Bo bo) {
        return toAjax(ab05Service.updateByBo(bo));
    }

    /**
     * 删除个人账户总账
     *
     * @param ID 主键串
     */
    @SaCheckPermission("yuanshidian:ab05:remove")
    @Log(title = "个人账户总账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ID}")
    public R<Void> remove(@NotNull(message = "主键不能为空") @PathVariable Long ID) {
        Ab05Bo ab05 = new Ab05Bo();
        ab05.setId(ID);
        ab05.setDelStatus(1L);
        return toAjax(ab05Service.updateByBo(ab05));
    }
}
